#!/bin/bash

echo '✅ start build skiko #'
cd /Users/peaceful_black/kn/skiko-ohrender/skiko

./gradlew clean
echo "✅ waiting cleaning skiko..."

./build-with-local-skia.sh
echo "✅ waiting building skiko..."

echo '✅ start build compose #'
cd /Users/peaceful_black/kn/ovCompose-multiplatform-core
./gradlew clean
echo "✅ waiting cleaning compose..."

./gradlew :mpp:publishComposeJbToMavenLocal -Pcompose.platforms=ohosArm64
echo "✅ waiting building compose..."

echo "✅ waiting building compose-arkts..."
cd /Users/peaceful_black/kn/ovCompose-multiplatform-core/compose/ui/ui-arkui/src/ohosArm64Main/cpp/composeApp

hvigorw --mode module -p product -p module=compose assembleHar

MULTIPLATFORM_CORE_DIR="/Users/peaceful_black/kn/ovCompose-multiplatform-core"
SAMPLE_DIR="/Users/peaceful_black/kn/ovCompose-sample"

echo "✅ copy compose.har"
cp "$MULTIPLATFORM_CORE_DIR/compose/ui/ui-arkui/src/ohosArm64Main/cpp/compose/build/default/outputs/default/compose.har" "/Users/peaceful_black/kn/ovCompose-sample/harmonyApp/entry/libs"

echo '✅ start build compose-sample #'
cd /Users/peaceful_black/kn/ovCompose-sample
./gradlew clean
echo "✅ waiting cleaning compose-sample..."

./gradlew linkDebugSharedOhosArm64
echo "✅ waiting building compose-sample..."

echo "✅ copy"
cp "$SAMPLE_DIR/composeApp/build/bin/ohosArm64/debugShared/libkn.so" "$SAMPLE_DIR/harmonyApp/entry/libs/arm64-v8a"
cp "$SAMPLE_DIR/composeApp/build/bin/ohosArm64/debugShared/libkn_api.h" "$SAMPLE_DIR/harmonyApp/entry/src/main/cpp/include/"
echo "✅ finish"